#ifndef ALGO_MATH_H
#define ALGO_MATH_H

#include "algo_type.h"

// MACROS
#define F_MAX(a,b)        ( (a) > (b) ? (a) : (b) )
#define F_MIN(a,b)        ( (a) < (b) ? (a) : (b) )
#define WITHIN(x,l,u)   ( ((x) >= (l)) && ((x) <= (u)) )
#define CLIP(x,u,l)     ( (x) > (u) ? (u) : ( (x) < (l) ? (l) : (x) ) )
#define ABS(a)          ( (a) < 0 ? -(a) : (a) )
#define SGN(a)          ( (a) < 0 ? -1 : 1  )
#define F_SQR(a)        ( ( (a)*(a) + PERCISION/2 ) / PERCISION )
#define F_MUL(a,b)      ( ( (a)*(b) + SGN(a)*SGN(b)*PERCISION/2 ) / PERCISION )
#define U_DIV(a,b)      ( ( (a) + (b)/2 ) / (b) )
#define S_DIV(a,b)      ( ( (a) + ( SGN(a)*ABS(b)/2 ) ) / (b) )
#define F_DIV(a,b)      ( ( (a) * PERCISION + ( SGN(a)*ABS(b)/2 ) ) / (b) )
#define NORM(x,u,l)     ( F_DIV(x-l,u-l) )
#define CLIP_NORM(x,u,l)  ( (x) > (u) ? (PERCISION) : ( (x) < (l) ? (0) : NORM(x,u,l) ) )


// Public functions declaration
void QuickSort(int32 *i32p_arr, int32 i32_startPos, int32 i32_endPos);
fixed32 WeightMean(fixed32 i32_value1, fixed32 i32_value2, fixed32 i32_weight1);
fixed32 Exp(fixed32 f32_exponent);
fixed32 Log(fixed32 f32_antilog);
fixed32 Pow(fixed32 f32_base, fixed32 f32_exponent);
uint32 Sqrt( uint32 u32_Value );

fixed32 Real(comp64 c64_value);
fixed32 Imag(comp64 c64_value);
fixed32 Modulus(comp64 c64_value);

#endif // ALGO_MATH_H
